/*
 * p11796.cpp
 *
 *  Created on: 2013-6-3
 *      Author: zy
 */

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

const double eps = 1e-6;
const int maxn = 60;
int T, A, B;
int sig(double d)
{
	return fabs(d) < eps ? 0 : d < 0 ? -1 : 1;
}
struct Point
{
	double x, y;
	Point()
	{
	}
	Point(double x, double y) :
		x(x), y(y)
	{
	}
	void set(double x, double y)
	{
		this->x = x;
		this->y = y;
	}
	void read()
	{
		scanf("%lf%lf", &x, &y);
	}
	double mod()
	{
		return sqrt(x * x + y * y);
	}
	Point friend operator -(Point a, Point b)
	{
		return Point(a.x - b.x, a.y - b.y);
	}
	Point friend operator +(Point a, Point b)
	{
		return Point(a.x + b.x, a.y + b.y);
	}
	Point friend operator *(Point a, double p)
	{
		return Point(a.x * p, a.y * p);
	}
	Point friend operator /(Point a, double p)
	{
		return Point(a.x / p, a.y / p);
	}
	bool friend operator ==(Point a, Point b)
	{
		return sig(a.x - b.x) == 0 && sig(a.y - b.y) == 0;
	}

};
Point P[maxn], Q[maxn];

double Min, Max;
double dot(Point a, Point b)
{
	return a.x * b.x + a.y * b.y;
}
double cross(Point o, Point a, Point b)
{
	return (a.x - o.x) * (b.y - o.y) - (b.x - o.x) * (a.y - o.y);
}
double dis(Point a, Point b)
{
	return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
double pointToSeg(Point o, Point a, Point b)
{
	if (a == b)
		return dis(o, a);
	Point v1 = b - a, v2 = o - a, v3 = o - b;
	if (sig(dot(v1, v2)) < 0)
		return v2.mod();
	else if (sig(dot(v1, v3)) > 0)
		return v3.mod();
	double d = dis(a, b);
	double s = cross(a, b, o) / d;
	return fabs(s);
}
void update(Point P, Point A, Point B)
{
	Min = min(Min, pointToSeg(P, A, B));
	Max = max(Max, (P - A).mod());
	Max = max(Max, (P - B).mod());
}

int main()
{
	scanf("%d", &T);
	for (int cas = 1; cas <= T; cas++)
	{
		scanf("%d%d", &A, &B);
		for (int i = 0; i < A; i++)
			P[i].read();
		for (int i = 0; i < B; i++)
			Q[i].read();
		double LenA = 0, LenB = 0;
		for (int i = 0; i < A - 1; i++)
			LenA += (P[i] - P[i + 1]).mod();
		for (int i = 0; i < B - 1; i++)
			LenB += (Q[i] - Q[i + 1]).mod();
		int Sa = 0, Sb = 0;
		Point Pa = P[0], Pb = Q[0];
		Min = 1e9;
		Max = -1e9;
		while (Sa < A - 1 && Sb < B - 1)
		{
			double La = (P[Sa + 1] - Pa).mod();
			double Lb = (Q[Sb + 1] - Pb).mod();
			double T = min(La / LenA, Lb / LenB);
			Point Va = (P[Sa + 1] - Pa) / La * T * LenA;
			Point Vb = (Q[Sb + 1] - Pb) / Lb * T * LenB;
			update(Pa, Pb, Pb + Vb - Va);
			Pa = Pa + Va;
			Pb = Pb + Vb;
			if (Pa == P[Sa + 1])
				Sa++;
			if (Pb == Q[Sb + 1])
				Sb++;
		}
		printf("Case %d: %d\n", cas, (int) (Max - Min + 0.5));
	}
	return 0;
}
